//
//  QKStatusCellTopView.m
//  QKWeibo-OC
//
//  Created by iMac_Kurt on 16/9/1.
//  Copyright © 2016年 Kurt_Qi. All rights reserved.
//

#import "QKStatusCellTopView.h"
#import <Masonry.h>
#import "UILabel+QKLabel.h"
#import <UIImageView+WebCache.h>

@interface QKStatusCellTopView ()
/// 用户头像
@property (nonatomic, strong) UIImageView *iconView;
/// 用户昵称
@property (nonatomic, strong) UILabel *nameLabel;
/// vip等级图标
@property (nonatomic, strong) UIImageView *vipLevelIconView;
/// 微博发布时间
@property (nonatomic, strong) UILabel *timeLabel;
/// 微博来源
@property (nonatomic, strong) UILabel *sourceLabel;
/// 用户认证类型 -1：没有人证 0：认证用户 2，3，5：企业认证 220：达人
@property (nonatomic, strong) UIImageView *memberTypeIconView;
@end

@implementation QKStatusCellTopView

//
- (void)setStatusViewModel:(QKStatusViewModel *)statusViewModel {
    _statusViewModel = statusViewModel;
    
    // 设置数据
    [self.iconView sd_setImageWithURL:statusViewModel.iconImageURL];
    [self.memberTypeIconView setImage:statusViewModel.menberTypeIcon];
    self.nameLabel.text = statusViewModel.status.user.screen_name;
    [self.vipLevelIconView setImage:statusViewModel.vipLevelIcon];
#warning TODO: setup data of timeLabel and sourceLabel
}


- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        //
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    // 添加子控件
    [self addSubview:self.iconView];
    [self addSubview:self.memberTypeIconView];
    [self addSubview:self.nameLabel];
    [self addSubview:self.vipLevelIconView];
    [self addSubview:self.timeLabel];
    [self addSubview:self.sourceLabel];
    
    // 自动布局
    // 头像
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(QKStatusCellMargin);
        make.left.equalTo(self.mas_left).offset(QKStatusCellMargin);
        make.width.equalTo(@(QKStatusCellIconWidth));
        make.height.equalTo(@(QKStatusCellIconWidth));
    }];
    // 会员认证种类
    [self.memberTypeIconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.iconView.mas_right);
        make.centerY.equalTo(self.iconView.mas_bottom);
    }];
    // 昵称
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconView.mas_top);
        make.left.equalTo(self.iconView.mas_right).offset(QKStatusCellMargin);
    }];
    // vip等级
    [self.vipLevelIconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconView.mas_top);
        make.left.equalTo(self.nameLabel.mas_right).offset(QKStatusCellMargin);
    }];
    // 发布时间
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.iconView.mas_bottom);
        make.left.equalTo(self.iconView.mas_right).offset(QKStatusCellMargin);
    }];
    // 微博来源
    [self.sourceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.iconView.mas_bottom);
        make.left.equalTo(self.timeLabel.mas_right).offset(QKStatusCellMargin);
    }];
    
}

#pragma mark - 懒加载控件
- (UIImageView *)iconView {
    if (_iconView == nil) {
        _iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"avatar_default_big"]];
    }
    return _iconView;
}

- (UIImageView *)memberTypeIconView {
    if (_memberTypeIconView == nil) {
        _memberTypeIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"avatar_vip"]];
    }
    return _memberTypeIconView;
}

- (UILabel *)nameLabel {
    if (_nameLabel == nil) {
        _nameLabel = [UILabel labelWithText:@"用户昵称" color:[UIColor darkGrayColor] fontSize:12];
    }
    return _nameLabel;
}

- (UIImageView *)vipLevelIconView {
    if (_vipLevelIconView == nil) {
        _vipLevelIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"common_icon_membership_expired"]];
    }
    return _vipLevelIconView;
}

- (UILabel *)timeLabel {
    if (_timeLabel == nil) {
        _timeLabel = [UILabel labelWithText:@"刚刚" color:[UIColor orangeColor] fontSize:12];
    }
    return _timeLabel;
}

- (UILabel *)sourceLabel {
    if (_sourceLabel == nil) {
        _sourceLabel = [UILabel labelWithText:@"7KurtBoy" color:[UIColor darkGrayColor] fontSize:12];
    }
    return _sourceLabel;
}

@end
